//Shot.cpp
/*
Shot class
Created by: Robert Wirthman
*/

#include "Shot.h"
#include <cmath>
using namespace std;

Shot::Shot()
{
	roomSize=7;
	forwardSpeed = 0.3;
	leftSpeed = 0; //left is negative, right is positive
	upSpeed = 0; // positive is up
	size = 0.25f;	//Temporary size 
	xPos = 0;
	yPos = 0;
	zPos = 0;
}

Shot::Shot(float mRoomSize)
{
	roomSize= mRoomSize;
	forwardSpeed = 0.3;
	leftSpeed = 0;
	upSpeed = 0;
	size = 0.25f;	//Temporary size 
	xPos = 0;
	yPos = 0;
	zPos = 0;
}

float Shot::getXPos(){
	return xPos;
}

float Shot::getYPos(){
	return yPos;
}

float Shot::getZPos(){
	return zPos;
}

float Shot::getForwardSpeed()
{
	return forwardSpeed;
}
float Shot::getLeftSpeed()
{
	return leftSpeed;
}
float Shot::getUpSpeed()
{
	return upSpeed;
}

float Shot::getSize()
{
	return size;
}

void Shot::setXPos(float x){
	xPos=x;
}

void Shot::setYPos(float y){
	yPos=y;
}

void Shot::setZPos(float z){
	zPos=z;
}

void Shot::setHorFacing(int f){
	horFacing = f;
}
void Shot::setVertFacing(int f){
	vertFacing = f;
}

int Shot::updatePositions()
{
	float tmpX = xPos+forwardSpeed*cos((float) horFacing * (float) 3.14159/(float)180) * cos((float) vertFacing * (float) 3.14159/ (float) 180);
	float tmpZ = zPos-(forwardSpeed*sin((float) horFacing * (float) 3.14159/(float)180) * cos((float) vertFacing * (float) 3.14159 / (float) 180));
	float tmpY = yPos+forwardSpeed*sin((float) vertFacing * (float) 3.14159/(float) 180);
	int inRoom = 1;

	if(tmpX > roomSize/2 - size/2) {
		xPos= roomSize/2 - size/2;
		inRoom = 0;
	}
	else if(tmpX < 0-roomSize/2 + size/2) {
		xPos= 0-roomSize/2 + size/2;
		inRoom = 0;
	}
	else {
		xPos= tmpX;
	}
	if(tmpZ > roomSize/2 - size/2) {
		zPos= roomSize/2 - size/2;
		inRoom = 0;
	}
	else if(tmpZ < 0-roomSize/2 + size/2) {
		zPos= 0-roomSize/2 + size/2;
		inRoom = 0;
	}
	else {
		zPos= tmpZ;
	}
	if(tmpY > roomSize/2 - size/2) {
		yPos = roomSize/2 - size/2;
		inRoom = 0;
	}
	else if(tmpY < 0-roomSize/2 + size/2) {
		yPos= 0-roomSize/2 + size/2;
		inRoom = 0;
	}
	else {
		yPos= tmpY;
	}
	return inRoom;
}
